import {
    clearDrawGeometry,
    getMapViewState,
} from "lark-map";
import QueryUtils from "@/utils/yc/QueryUtils";
import LayerUtils from "@/utils/yc/LayerUtils";
import SymbolUtils from "@/utils/yc/SymbolUtils";
/**
 * 
 */
export default {
    data() {
        return {
            view: {}, //地图对象
            districtFeature: null,//初始化行政区
        }
    },
    methods: {
        /**
         * 初始化地图
         * @param {*} view 
         */
        async initLoad(view) {
            this.view = view?.mapView;
            if (this.view) {
                this.$emit("initMapView", this.view);
                LayerUtils.createAreaLayer(this.view);
                LayerUtils.createRenderDrawLayer(this.view);
                this.districtFeature = await QueryUtils.queryAreaByCode("xzq", this.view, "150125");
                // if(this.districtFeature){
                //     this.districtFeature.symbol = SymbolUtils.AREA_RENDER
                //     LayerUtils.getAreaLayer(this.view).add(this.districtFeature)
                //     this.view.goTo(this.districtFeature)
                // }
                let owner = this;
                let type = this.$route.name;
                if (type === "ecoCoord" || type === "ecoSlicing") {
                    this.view.on("click", function (event) {
                        if (getMapViewState() === "occupied") return;
                        owner.$emit("mapClickHandler", event);
                    });
                }
            }
        },

        /**
         * 设置地图是否显示
         */
        setMapServiceLayerVisible() {
            clearDrawGeometry({ view: this.view });
            this.view.graphics.removeAll();
            let routeConfigData = this.$route["meta"]["mapServiceConfig"];
            LayerUtils.setMapServiceLayerVisible(routeConfigData, this.view);
        },
    },
    mounted() {
        this.$eventBus.$on("drawPolygonHandler", this.drawPolygonCompelteHandler);
    },
    destroyed() {
        this.$eventBus.$off("drawPolygonHandler");
    },
    /**
     * 监听路由、地图
     */
    watch: {
        view: {
            handler: function (newval, oldval) {
                this.setMapServiceLayerVisible();
            }
        }
    }
}